Skip to content

Apply custom HTTP headers in remote server calls#1549

Open
timw wants to merge 1 commit into
chains-project:mainfrom
indexity-io:feature/remote-auth-headers
Open

Apply custom HTTP headers in remote server calls#1549
timw wants to merge 1 commit into
chains-project:mainfrom
indexity-io:feature/remote-auth-headers

Conversation

@timw
Copy link
Copy Markdown
Contributor

@timw timw commented Apr 17, 2026

Some private repositories (e.g. Gitlab) require custom HTTP headers containing access tokens for requests to the Maven package registry to succeed - e.g. requests for .sha1 files and direct artifact downloads.

This PR adds headers configured for the server/repository in the Maven HTTP transport configuration (e.g. in the server.xml used for the session) to the remote server requests.

This avoids checksum calculation failures for private repositories, which, aside from excluding them from validation with the remote calculator, also creates issues if the lockfile is subsequently validated with the local checksum calculator.

This doesn't currently support the authentication mechanisms (e.g. password auth) supported by the Mavent HTTP transport, as that would require a bit more refactoring, and headers are sufficient for our requirements.

Apply custom HTTP headers to remote server requests (e.g. containing access tokens for private repositories), using the standard Maven HTTP transport configuration as per: https://maven.apache.org/guides/mini/guide-resolver-transport.html
@timw timw force-pushed the feature/remote-auth-headers branch from 387ff99 to b4253e1 Compare April 17, 2026 02:30
Copy link
Copy Markdown
Member

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the idea! I hope you have tried this with private GitLab repositories and it works. There does not seem to be an easy way to add tests for it.

Also, does Maven Central verify where the request is coming from? If it is from a private GitLab CI, does it reject the request? I don't clearly understand why would the registry deny the request.

var serverConfig = server.getConfiguration();
if (serverConfig instanceof Xpp3Dom) {
var config = (Xpp3Dom) serverConfig;
var headers = config.getChild("httpHeaders");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var headers = config.getChild("httpHeaders");
var headers = config.getChild("httpConfiguration");

httpConfiguration seems correct based on the documentation here. This documentation also seems pretty up-to-date.

}
}
}
var requestTimeout = config.getChild("requestTimeout");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see requestTimeout in the same documentation. It is either connectionTimout, readTimeout, or timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants